| API Documentation |  |

- MAIN PAGE
- NAMESPACES
- CLASSES

Public Member Functions | List of all members
nkMemory::String Class Referencefinal

Class holding information about a string, with ownership over the data. More...

## Public Member Functions
| String () noexcept
| String (const char *data) noexcept
| String (unsigned long long size) noexcept
| String (const char *data, unsigned long long size) noexcept
| String (StringView view) noexcept
| String (const String &other) noexcept
| String (String &&other) noexcept
| ~String ()
char * | getData () const
unsigned long long | getSize () const
bool | empty () const
char | front () const
char & | front ()
char | back () const
char & | back ()
const char * | begin () const
char * | begin ()
const char * | end () const
char * | end ()
void | clear ()
void | resize (unsigned long long size)
BufferCast< StringView > | split (StringView separator)
String & | operator= (const char *data) noexcept
String & | operator= (StringView other) noexcept
String & | operator= (const String &other) noexcept
String & | operator= (String &&other) noexcept
char | operator[] (unsigned long long index) const
char & | operator[] (unsigned long long index)
void | operator+= (char value)
void | operator+= (StringView other)
String | operator+ (char c) const
String | operator+ (const char *other) const
String | operator+ (StringView other) const
bool | operator== (const char *other) const
bool | operator== (StringView other) const
bool | operator!= (const char *other) const
bool | operator!= (StringView other) const
template<typename T = std::string>
| String (const std::string &str) noexcept
template<typename T = std::string_view>
| String (const std::string_view &str) noexcept
| operator std::string () const
| operator std::string_view () const
| operator nkLog::String () const
| operator nkLog::StringView () const
String & | operator= (const std::string &data)
String & | operator= (const std::string_view &data)

## Detailed Description

Class holding information about a string, with ownership over the data.

This class will abstract a chain of characters and offer some utility to help manipulating them. The aim of this class is not to replace std::string within a codebase, but rather to offer a safe data exchange class from an app to the dlls, and the other way around. This class being fully exported, it doesn't suffer from the caveats a template can have in such situations.

To help in this dialog between app and dlls, the class is thought to be as transparent as possible between const char*, std::string and other widespread way of representing strings. Typical usage would just be to use standard structures in your app and benefit from the automatic converions from one type to another.

The String class will copy over memory and keep it in its own safe allocation. If memory safety is required, use this class. However, this can be slower as memory needs to be allocated and shuffled around. Unless this is required, prefer to use the StringView variant.

## Constructor & Destructor Documentation

## ◆ String() [1/9]

nkMemory::String::String | ( |  | ) |
| noexcept

Default constructor. Will default to a nullptr data and a size of 0.

## ◆ String() [2/9]

nkMemory::String::String | ( | const char * | data | ) |
| noexcept

Const char* constructor. Provided memory location will be copied based on its length. Be sure provided data is null-terminated.

Parameters

  data | The pointer to the chain of characters to take over.

## ◆ String() [3/9]

nkMemory::String::String | ( | unsigned long long | size | ) |
| noexcept

Pre-allocation constructor. Data will be allocated depending on the size requested, and set to 0.

Parameters

  size | The size of the chain to create, in number of chars.

## ◆ String() [4/9]

nkMemory::String::String | ( | const char * | data,
|  | unsigned long long | size
| ) |  |
| noexcept

Guided const char* constructor. Provided memory location will be copied based on the size given. Prefer this constructor over the const char* constructor if you know the size required.

Parameters

  data | The pointer to the chain of characters to take over.
  size | The size of the chain provided, in number of chars.

## ◆ String() [5/9]

nkMemory::String::String | ( | StringView | view | ) |
| noexcept

View constructor. Memory location pointed by view will be copied over.

Parameters

  view | The view to copy the memory from.

## ◆ String() [6/9]

nkMemory::String::String | ( | const String & | other | ) |
| noexcept

Copy constructor.

Parameters

  other | The string to copy from.

## ◆ String() [7/9]

nkMemory::String::String | ( | String && | other | ) |
| noexcept

Move constructor.

Parameters

  other | The string to move over.

## ◆ ~String()

nkMemory::String::~String | ( |  | ) |

Destructor.

## ◆ String() [8/9]

template<typename T = std::string>

nkMemory::String::String | ( | const std::string & | str | ) |
| noexcept

Standard string constructor. The string provided will be copied over.

Parameters

  str | The string to copy.

## ◆ String() [9/9]

template<typename T = std::string_view>

nkMemory::String::String | ( | const std::string_view & | str | ) |
| noexcept

Standard string view constructor. The view provided will be copied over.

Parameters

  str | The view to copy.

## Member Function Documentation

## ◆ getData()

char* nkMemory::String::getData | ( |  | ) | const

Returns
  A pointer over the memory of the string.

## ◆ getSize()

unsigned long long nkMemory::String::getSize | ( |  | ) | const

Returns
  The size of the string, in number of chars.

## ◆ empty()

bool nkMemory::String::empty | ( |  | ) | const

Returns
  Whether the string is of size 0, aka empty (true) or not (false).

## ◆ front() [1/2]

char nkMemory::String::front | ( |  | ) | const

Returns
  The first char in the string.

## ◆ front() [2/2]

char& nkMemory::String::front | ( |  | ) |

Returns
  The first char in the string.

## ◆ back() [1/2]

char nkMemory::String::back | ( |  | ) | const

Returns
  The last char in the string.

## ◆ back() [2/2]

char& nkMemory::String::back | ( |  | ) |

Returns
  The last char in the string.

## ◆ begin() [1/2]

const char* nkMemory::String::begin | ( |  | ) | const

Returns
  A pointer over the beginning of the memory spot.

## ◆ begin() [2/2]

char* nkMemory::String::begin | ( |  | ) |

Returns
  A pointer over the beginning of the memory spot.

## ◆ end() [1/2]

const char* nkMemory::String::end | ( |  | ) | const

Returns
  A pointer right past the end of the memory spot.

## ◆ end() [2/2]

char* nkMemory::String::end | ( |  | ) |

Returns
  A pointer right past the end of the memory spot.

## ◆ clear()

void nkMemory::String::clear | ( |  | ) |

Clears the string and frees its memory, returning it to its default state.

## ◆ resize()

void nkMemory::String::resize | ( | unsigned long long | size | ) |

Resizes the internal memory of the string. Existing chars will be kept, while newly introduced ones will be set to 0.

Parameters

  size | The new size the string should take, in number of chars.

## ◆ split()

BufferCast<StringView> nkMemory::String::split | ( | StringView | separator | ) |

Splits a string into multiple tokens.

Parameters

  separator | The separator pattern to use to split the string.

Returns
  The split result, one entry for each token found.

## ◆ operator=() [1/6]

String& nkMemory::String::operator= | ( | const char * | data | ) |
| noexcept

Const char* assignment operator.

Parameters

  data | The pointer over the memory to copy.

## ◆ operator=() [2/6]

String& nkMemory::String::operator= | ( | StringView | other | ) |
| noexcept

View assignment operator.

Parameters

  other | The view over memory to copy.

## ◆ operator=() [3/6]

String& nkMemory::String::operator= | ( | const String & | other | ) |
| noexcept

String copy assignment operator.

Parameters

  other | The string to copy.

## ◆ operator=() [4/6]

String& nkMemory::String::operator= | ( | String && | other | ) |
| noexcept

String move assignment operator.

Parameters

  other | The string to move over.

## ◆ operator[]() [1/2]

char nkMemory::String::operator[] | ( | unsigned long long | index | ) | const

Const access operator.

Parameters

  index | The index of the char to access.

## ◆ operator[]() [2/2]

char& nkMemory::String::operator[] | ( | unsigned long long | index | ) |

Access operator.

Parameters

  index | The index of the char to access.

## ◆ operator+=() [1/2]

void nkMemory::String::operator+= | ( | char | value | ) |

Char append operator.

Parameters

  value | The char to append to the string.

## ◆ operator+=() [2/2]

void nkMemory::String::operator+= | ( | StringView | other | ) |

View append operator.

Parameters

  other | The view to append to the string.

## ◆ operator+() [1/3]

String nkMemory::String::operator+ | ( | char | c | ) | const

Char concatenation operator.

Parameters

  c | The char to concatenate.

Returns
  The result of the concatenation of calling string with the char provided.

## ◆ operator+() [2/3]

String nkMemory::String::operator+ | ( | const char * | other | ) | const

Char chain concatenation operator.

Parameters

  other | The chain to concatenate with.

Returns
  The result of the concatenation of calling string with the chain provided.

## ◆ operator+() [3/3]

String nkMemory::String::operator+ | ( | StringView | other | ) | const

View concatenation operator.

Parameters

  other | The view to concatenate with.

Returns
  The result of the concatenation of calling string with the view provided.

## ◆ operator==() [1/2]

bool nkMemory::String::operator== | ( | const char * | other | ) | const

Const char* equality operator.

Parameters

  other | The const char* to check equality with.

Returns
  True if chains are the same, false otherwise.

## ◆ operator==() [2/2]

bool nkMemory::String::operator== | ( | StringView | other | ) | const

View equality operator.

Parameters

  other | The view to check equality with.

Returns
  True if chains are the same, false otherwise.

## ◆ operator!=() [1/2]

bool nkMemory::String::operator!= | ( | const char * | other | ) | const

Const char* inequality operator.

Parameters

  other | The const char* to check equality with.

Returns
  True if chains are difference, false otherwise.

## ◆ operator!=() [2/2]

bool nkMemory::String::operator!= | ( | StringView | other | ) | const

View inequality operator.

Parameters

  other | The view to check equality with.

Returns
  True if chains are difference, false otherwise.

## ◆ operator std::string()

nkMemory::String::operator std::string | ( |  | ) | const

Conversion operator, to std::string.

## ◆ operator std::string_view()

nkMemory::String::operator std::string_view | ( |  | ) | const

Conversion operator, to std::string_view.

## ◆ operator nkLog::String()

nkMemory::String::operator nkLog::String | ( |  | ) | const

Conversion operator, to nkLog::String.

## ◆ operator nkLog::StringView()

nkMemory::String::operator nkLog::StringView | ( |  | ) | const

Conversion operator, to nkLog::StringView.

## ◆ operator=() [5/6]

String& nkMemory::String::operator= | ( | const std::string & | data | ) |

Templated assignment operator.

Parameters

  data | The string to assign.

Returns
  A reference over calling string, once updated.

## ◆ operator=() [6/6]

String& nkMemory::String::operator= | ( | const std::string_view & | data | ) |

Templated assignment operator.

Parameters

  data | The string view to assign.

Returns
  A reference over calling string, once updated.

The documentation for this class was generated from the following file:

- Documentation/Headers/NilkinsMemory/Containers/String.h